package com.tangsm.spring.boot.deferred.result.service.impl;

import com.tangsm.spring.boot.deferred.result.domain.vo.Result;
import com.tangsm.spring.boot.deferred.result.service.TaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * 任务服务接口实现
 *
 * @author tangsm
 */
@Service
public class TaskServiceImpl implements TaskService {
    private static final Logger log = LoggerFactory.getLogger(TaskServiceImpl.class);
    private long millis = 1000L;

    /**
     * 获取结果
     *
     * @return 响应数据
     */
    public Result<String> getResult() {
        log.info("任务开始执行，持续等待中...");
        try {
            log.info("任务等待：{}毫秒", millis);
            Thread.sleep(millis);
            millis += 100;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("任务处理完成");
        return new Result<>(0, "操作成功", UUID.randomUUID().toString().replace("-", ""));
    }
}
